<template>
	<view>
		<anil-seat
			v-if="seatList.length > 1"
			:title="base_data.filmName"
			:info="base_data.showDate + ' ' + base_data.showTime + ' | ' + base_data.showVersionType"
			:room-name="base_data.hallName.split('厅')[0] + '厅'"
			:seat-data="seatList"
			:max="4"
			@confirm="onConfirmSeat"
		></anil-seat>
		<MyLoading :loading="loading" animation_updown="true"></MyLoading>
	</view>
</template>

<script>
import MyLoading from '@/components/my-loading/my-loading.vue';
import Route from '../../utils/route.js';
import Login from '../../utils/login.js';
export default {
	components: {
		MyLoading
	},
	data() {
		return {
			// 加载动画
			loading:true,
			// 基础数据
			base_data: {},
			// 座位数据
			seatList: []
			// 已选座位
		};
	},
	async onLoad(e) {
		// 接参
		this.base_data = JSON.parse(e.data);
		// 设置标题
		uni.setNavigationBarTitle({
			title: this.base_data.filmName
		});
		// 获取座位数据
		await this.getSeatList();
	},
	methods: {
		// 获取座位数据
		async getSeatList() {
			let res = await Route.seat_list({
				showId: this.base_data.showId,
				netPrice: this.base_data.netPrice,
				scheduleArea: this.base_data.scheduleArea
			});
			this.seatList = res.list;
			this.loading = false
		},
		// 确认选座
		async onConfirmSeat(items) {
			await Login.isLogin();
			await Login.isPhone();
			let seatList = [];
			let Price = 0;
			let vipPrice = 0;
			for (var i = 0; i < items.length; i++) {
				seatList.push(items[i].seatNo);
				Price += items[i].Price;
				vipPrice += items[i].vipPrice;
			}
			let time = this.base_data.showDate + ' ' + this.base_data.showTime;
			let data = {
				filmId: this.base_data.filmId,
				showId: this.base_data.showId,
				showTime: new Date(time.replace(/-/g,'/')).getTime() / 1000,
				cinemaName: this.base_data.cinemaName,
				hallName: this.base_data.hallName,
				seatList: seatList,
				seatLength: seatList.length,
				Price: Price,
				vipPrice: vipPrice
			};
			// #ifdef MP-WEIXIN
			uni.requestSubscribeMessage({
				tmplIds: ['H4fbW4brR-XdUvNgfqKf2Qbw8bcattXCFvKCH8zdrG0', 'k9US67UeFpf8NnPwwJ0T5ip8ahD1uRfIejEf7WNlPeg'], //需要授权的消息模板类型
				success(res) {
				},
				fail(err) {
					return uni.showToast({
						title: '可能错过重要信息通知，赶紧打开吧',
						duration: 1500,
						icon: 'none'
					});
				},
				complete() {
					uni.redirectTo({
						url: '../pay/pay?data=' + JSON.stringify(data)
					});
				}
			});
			// #endif
		}
	}
};
</script>

<style lang="scss">
page {
	background: #f8f8f8;
}
</style>
